package com.aust.dynamicProxy.test3;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class UserHandle implements InvocationHandler {
    private Object target;

    public UserHandle(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("login") || method.getName().equals("deleteUsers") || method.getName().equals("selectUsers")) {
            long startTime = System.currentTimeMillis();
            Object object = method.invoke(target, args);
            long endTime = System.currentTimeMillis();
            System.out.println(method.getName() + "方法执行耗时：" + (endTime - startTime) + "ms");
            return object;
        } else {
            Object object = method.invoke(target, args);
            return object;
        }
    }
}
